package com.kc.business.service.impl;

import com.kc.business.domain.KcAppVersion;
import com.kc.business.mapper.KcAppVersionMapper;
import com.kc.business.service.KcAppVersionService;
import com.kc.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author TP
 * @date 2021-01-30 18:32
 */
@Service
public class KcAppVersionServiceImpl implements KcAppVersionService {

    @Autowired
    private KcAppVersionMapper appVersionMapper;

    @Override
    public List<KcAppVersion> getList(KcAppVersion appVersion) {
        return appVersionMapper.getList(appVersion);
    }

    @Override
    public int add(KcAppVersion appVersion) {
        if (appVersion != null) {
            return appVersionMapper.insertSelective(appVersion);
        }
        return 0;
    }

    @Override
    public List<KcAppVersion> getByVersionAndOsType(String version, Integer osType) {
        if (StringUtils.isNotEmpty(version) && osType != null) {
            KcAppVersion appVersion = new KcAppVersion();
            appVersion.setVersion(version);
            appVersion.setOsType(osType);
            return appVersionMapper.select(appVersion);
        }
        return null;
    }

    @Override
    public int delete(Integer id) {
        if (id != null && id > 0) {
            return appVersionMapper.deleteByPrimaryKey(id);
        }
        return 0;
    }

    @Override
    public KcAppVersion getLatestVersion(Integer osType) {
        if (osType != null) {
            return appVersionMapper.getLatestByOsType(osType);
        }
        return null;
    }
}
